<?php
namespace app\lib\task;
use think\Config;
use app\lib\redis\Predis;

/**
 * swoole异步任务处理
 */
class Task
{
	/*
	通过task异步任务实时发送数赛况据到客户端
	@pushData 需要发送的数据
	@$server swoole_ws对象
	 */
	public function pushDataToLive($pushData,$server){

		$members = Predis::instance()->sMembers(Config::get('redis.live_members'));
    	foreach ($members as $k => $val) {
    		$server->push($val,json_encode($pushData));
    	}
	}

	/*
	通过task异步任务实时发送数聊天据到客户端
	@pushData 需要发送的数据
	@$server swoole_ws对象
	 */
	public function pushDataToChat($pushData,$server){

		foreach ($server->ports[1]->connections as $val) {
            $server->push($val,json_encode($pushData));
        }
	}
	
}